home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / modelers / geomview / source.lha / Geomview / src / bin / transformer / transformer.main.c < prev   
C/C++ Source or Header  |  1993-02-05  |  5KB  |  225 lines

  1. #include <math.h>
  2. #include "geom.h"
  3. #include "transform.h"
  4. #include "transform3.h"
  5. #include "forms.h"
  6. #include "panel.h"
  7.  
  8. Transform T;
  9. FL_OBJECT *t[4][4];
  10.  
  11. void set_input_float(FL_OBJECT *obj, float val);
  12. float get_input_float(FL_OBJECT *obj);
  13.  
  14. main() {
  15.  
  16.   foreground();
  17.  
  18.   create_the_forms();
  19.  
  20.   t[0][0] = t00;
  21.   t[0][1] = t01;
  22.   t[0][2] = t02;
  23.   t[0][3] = t03;
  24.   t[1][0] = t10;
  25.   t[1][1] = t11;
  26.   t[1][2] = t12;
  27.   t[1][3] = t13;
  28.   t[2][0] = t20;
  29.   t[2][1] = t21;
  30.   t[2][2] = t22;
  31.   t[2][3] = t23;
  32.   t[3][0] = t30;
  33.   t[3][1] = t31;
  34.   t[3][2] = t32;
  35.   t[3][3] = t33;
  36.  
  37.   fl_set_object_shortcut(RotateButton, "R");
  38.   fl_set_object_shortcut(TranslateButton, "T");
  39.   fl_set_object_shortcut(ScaleButton, "S");
  40.   fl_set_object_shortcut(ApplyButton, "a ");
  41.   fl_set_object_shortcut(SetButton, "s");
  42.   fl_set_object_shortcut(ReadButton, "r");
  43.   fl_set_object_shortcut(IdentityButton, "i");
  44.   fl_set_object_shortcut(DoneButton, "q");
  45.  
  46.   fl_set_button(actGeom, 1);
  47.  
  48.   set_input_float(RotationMeasure, 10);
  49.   fl_set_button(RotationAxisX, 1);
  50.   fl_set_button(RotationMeasure, 1);
  51.  
  52.   set_input_float(TranslationMeasure, 1);
  53.   fl_set_button(TranslationAxisX, 1);
  54.  
  55.   fl_set_button(ScaleX, 1);
  56.   fl_set_button(ScaleY, 1);
  57.   fl_set_button(ScaleZ, 1);
  58.   set_input_float(ScaleMeasure, 2);
  59.  
  60.   fl_set_button(RotateModeButton, 1);
  61.   fl_show_object(RotateGroup);
  62.   fl_hide_object(TranslateGroup);
  63.   fl_hide_object(ScaleGroup);
  64.  
  65.   fl_show_form(TransForm, FL_PLACE_SIZE, TRUE, "Transformer");
  66.   ReadProc(NULL, 0);
  67.   while (1) fl_do_forms();
  68.   
  69. }
  70.  
  71.  
  72. void set_input_float(FL_OBJECT *obj, float val) {
  73.   char buf[255];
  74.   sprintf(buf, "%.2f", val);
  75.   fl_set_input(obj, buf);
  76. }
  77.  
  78. float get_input_float(FL_OBJECT *obj) {
  79.   float f;
  80.   sscanf(fl_get_input(obj), "%f", &f);
  81.   return f;
  82. }
  83.  
  84.  
  85. void SetPanel(Transform T) {
  86.   int i, j;
  87.  
  88.   for (i = 0; i < 4; i++)
  89.     for (j = 0; j < 4; j++) 
  90.       set_input_float(t[i][j], T[i][j]);
  91. }
  92.  
  93. void GetPanel(Transform T) {
  94.   int i, j;
  95.  
  96.   for (i = 0; i < 4; i++)
  97.     for (j = 0; j < 4; j++) 
  98.       T[i][j] = get_input_float(t[i][j]);
  99.  
  100. }
  101.  
  102.  
  103. void RotateButtonProc(FL_OBJECT *o, long val) {
  104.   float f;
  105.  
  106.   f = get_input_float(RotationMeasure) * 2.0 * M_PI / 360.0;
  107.   printf("(transform %s targetcam rotate %f %f %f)",
  108.      (fl_get_button(actGeom) ? 
  109.       "targetgeom targetgeom" : "targetcam targetcam"),
  110.      (fl_get_button(RotationAxisX) ? f : 0.0),
  111.      (fl_get_button(RotationAxisY) ? f : 0.0),
  112.      (fl_get_button(RotationAxisZ) ? f : 0.0));
  113.   fflush(stdout);
  114.  
  115.   ReadProc(NULL, 0);
  116.  
  117. }
  118.  
  119.  
  120. void TranslateButtonProc(FL_OBJECT *o, long val) {
  121.   float f;
  122.  
  123.   f = get_input_float(TranslationMeasure);
  124.   printf("(transform %s targetcam translate %f %f %f)",
  125.      (fl_get_button(actGeom) ? 
  126.       "targetgeom targetgeom" : "targetcam targetcam"),
  127.      (fl_get_button(TranslationAxisX) ? f : 0.0),
  128.      (fl_get_button(TranslationAxisY) ? f : 0.0),
  129.      (fl_get_button(TranslationAxisZ) ? f : 0.0));
  130.   fflush(stdout);
  131.  
  132.   ReadProc(NULL, 0);
  133.     
  134. }
  135.  
  136.  
  137. void ScaleButtonProc(FL_OBJECT *o, long val) {
  138.   float f;
  139.  
  140.   f = get_input_float(ScaleMeasure);
  141.   if (!fl_get_button(actGeom)) return;
  142.   printf("(scale targetgeom %f %f %f)", 
  143.      fl_get_button(ScaleX) ? f : 1.0,
  144.      fl_get_button(ScaleY) ? f : 1.0,
  145.      fl_get_button(ScaleZ) ? f : 1.0);
  146.   fflush(stdout);
  147.   ReadProc(NULL, 0);
  148. }
  149.  
  150.  
  151. void ApplyProc(FL_OBJECT *o, long val) {
  152.   Transform T;
  153.   GetPanel(T);
  154.   printf("(xform %s { ", fl_get_button(actGeom) ? "targetgeom" : "targetcam" );
  155.   fputtransform(stdout, 1, &T[0][0], 0);
  156.   printf(" } )");
  157.   fflush(stdout);
  158. }
  159.  
  160.  
  161. void SetProc(FL_OBJECT *o, long val) {
  162.   Transform T;
  163.   GetPanel(T);
  164.   printf("(xform-set %s { ",
  165.      fl_get_button(actGeom) ? "targetgeom" : "targetcam" );
  166.   fputtransform(stdout, 1, &T[0][0], 0);
  167.   printf(" } ) ");
  168.   fflush(stdout);
  169. }
  170.  
  171.  
  172. void ReadProc(FL_OBJECT *o, long val) {
  173.   char buf[255];
  174.   Transform T;
  175.  
  176.   printf("(if (= (real-id target) (real-id World)) ");
  177.   printf("(write transform - %s universe) ",
  178.      fl_get_button(actGeom) ? "targetgeom" : "targetcam" );
  179.   printf("(write transform - %s world))\n",
  180.      fl_get_button(actGeom) ? "targetgeom" : "targetcam" );
  181.   fflush(stdout);
  182.   scanf("%s {", buf);
  183.   fgettransform(stdin, 1, &T[0][0], 0);
  184.   scanf("%s", buf);
  185.   SetPanel(T);
  186. }
  187.  
  188.  
  189. void IdentityProc(FL_OBJECT *o, long val) {
  190.   
  191.   SetPanel(TM_IDENTITY);
  192.  
  193. }
  194.  
  195.  
  196. void DoneProc(FL_OBJECT *o, long val) {
  197.   exit(0);
  198. }
  199.  
  200.  
  201.  
  202. void RotateMode(FL_OBJECT *o, long val) {
  203.   fl_freeze_form(TransForm);
  204.   fl_hide_object(TranslateGroup);
  205.   fl_hide_object(ScaleGroup);
  206.   fl_show_object(RotateGroup);
  207.   fl_unfreeze_form(TransForm);
  208. }
  209.  
  210. void TranslateMode(FL_OBJECT *o, long val) {
  211.   fl_freeze_form(TransForm);
  212.   fl_hide_object(RotateGroup);
  213.   fl_hide_object(ScaleGroup);
  214.   fl_show_object(TranslateGroup);
  215.   fl_unfreeze_form(TransForm);
  216. }
  217.  
  218. void ScaleMode(FL_OBJECT *o, long val) {
  219.   fl_freeze_form(TransForm);
  220.   fl_hide_object(RotateGroup);
  221.   fl_hide_object(TranslateGroup);
  222.   fl_show_object(ScaleGroup);
  223.   fl_unfreeze_form(TransForm);
  224. }
  225.